package com.tsingteng.cosfun.widget.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.common.Constant;

/**
 * 描述 :
 * 创建人: 肖利.
 * 时间:2018/10/11
 * qq(872179966)
 */

public class BlindPhoneDialog {

    private Activity activity;
    private Dialog dialog;
    private TextView mGoBlindTv;
    private TextView mPassOffTv;
    private BindPhoneListener mBindPhoneListener;
    public BlindPhoneDialog(Activity activity,BindPhoneListener listener) {
        this.activity = activity;
        this.mBindPhoneListener = listener;
        initView();
    }

    private void initView() {
        dialog = new Dialog(activity, R.style.dialog);
        dialog.setContentView(R.layout.dialog_blind_phone);
        mGoBlindTv = dialog.findViewById(R.id.go_blind_tv);
        mPassOffTv = dialog.findViewById(R.id.pass_off_tv);
        mPassOffTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dissMiss();
                mBindPhoneListener.onBindPhoneListener(Constant.PASSOFF);
            }
        });
        mGoBlindTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dissMiss();
                mBindPhoneListener.onBindPhoneListener(Constant.BLINDGO);
            }
        });
    }



    public void show() {
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams attributes = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER);
        DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics();// 获取屏幕宽、高用
        attributes.width = (int) (displayMetrics.widthPixels * 0.6); // 高度设置为屏幕的0.6
        dialogWindow.setAttributes(attributes);
        dialog.show();
    }

    public void dissMiss() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }
    public interface  BindPhoneListener{
        void onBindPhoneListener(String type);
    }
}
